<!-- html代码 -->
<template>
    <div>
        <Title :title="title"></Title>
        <div ref="bottom2" style="height: 150px; margin-top: 15px;"></div>
    </div>
</template>
<script>
import { Area } from '@antv/g2plot';
import { get } from '../../utils/request';
import { mapState } from 'vuex';
import moment from 'moment';
export default {
    data() {
        return {
            title: '监测点信息',
            params: {
                page: 1,
                pageSize: 51
            },
            pmData: [],
            Area: null
        }
    },
    computed: {
        ...mapState(['ed'])
    },
    watch: {
        ed: {
            handler(n, o) {
                this.params.device_id = n.device_id;
                this.params.engineer_id = n.engineer_id;
                this.getPmData();
                this.Area.changeData(this.pmData);
            },
            deep: true
        }
    },
    methods: {
        loadArea() {
            this.Area = new Area(this.$refs.bottom2, {
                data: this.pmData,
                xField: 'insert_time',
                yField: 'pm25',
                xAxis: {
                    label: {
                        style: {
                            fill: 'white'
                        }
                    }
                },
                yAxis: {
                    label: {
                        style: {
                            fill: 'white'
                        }
                    }
                },
                areaStyle: () => {
                    return {
                        fill: 'l(270) 0:#ffffff 0.5:#7ec2f3 1:#1890ff',
                    };
                },
                label: {
                    style: {
                        fill: 'white',
                    }
                },
                animation: {
                    appear: {
                        animation: 'wave-in',
                        duration: 5000,
                    },
                },
                tooltip: {
                    domStyles: {
                        "g2-tooltip": {
                            backgroundColor: '#147',
                            color: 'white',
                            fontSize: 20
                        }
                    }
                },
                state: {
                    active: {
                        style: {
                            shadowBlur: 4,
                            stroke: '#000',
                            fill: 'red',
                        },
                    },
                },
                interactions: [{ type: 'marker-active' }],
            });
            this.Area.render();
        },
        async getPmData() {
            let res = await get('/dashboard/pageQueryTodayData', this.params);
            console.log(res, '获取响应');
            res.data.list.forEach(function (item, index, arr) {
                arr[0].pm25 = 30;
                item.insert_time = moment(item.insert_time).format('HH:mm');
            });
            let temp = [];
            res.data.list.forEach((item, index, arr) => {
                if (index % 10 == 0) {
                    temp.push(arr[index])
                }
            })
            this.pmData = temp;
        }
    },
    async mounted() {
        await this.getPmData();
        this.loadArea();
    }
}
</script>
<style lang="less" scoped></style>